/**
 * jar包管理管理初始化
 */
var JarPackage = {
    id: "JarPackageTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
JarPackage.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'jar包名', field: 'jarName', visible: true, align: 'center', valign: 'middle'},
            {title: 'jar包别名', field: 'jarPackageName', visible: true, align: 'center', valign: 'middle'},
            {title: 'jar类名', field: 'jarClass', visible: true, align: 'center', valign: 'middle'},
            {title: '函数名', field: 'functionName', visible: true, align: 'center', valign: 'middle'},
            {title: '参数', field: 'param', visible: true, align: 'center', valign: 'middle'},
            {title: '版本', field: 'jarVersion', visible: true, align: 'center', valign: 'middle'},
            {title: '地址', field: 'url', visible: true, align: 'center', valign: 'middle'},
            {title: '密钥', field: 'md5', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},
            {title: '是否使用', field: 'isUse', visible: true, align: 'center', valign: 'middle',formatter:isUseFormat},
            {title: '是否实例', field: 'isInstance', visible: true, align: 'center', valign: 'middle'},
            {title: '排序', field: 'jarSort', visible: true, align: 'center', valign: 'middle'},
            {title: '时间', field: 'date', visible: true, align: 'center', valign: 'middle'}
    ];
};
function isUseFormat(value){
    return value==1?"使用":"停用";
}
/**
 * 检查是否选中
 */
JarPackage.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        JarPackage.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加jar包管理
 */
JarPackage.openAddJarPackage = function () {
    var index = layer.open({
        type: 2,
        title: '添加jar包管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/jarPackage/jarPackage_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看jar包管理详情
 */
JarPackage.openJarPackageDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'jar包管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/jarPackage/jarPackage_update/' + JarPackage.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除jar包管理
 */
JarPackage.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/jarPackage/delete", function (data) {
            Feng.success("删除成功!");
            JarPackage.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("jarPackageId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询jar包管理列表
 */
JarPackage.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    JarPackage.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = JarPackage.initColumn();
    var table = new BSTable(JarPackage.id, "/jarPackage/list", defaultColunms);
    table.setPaginationType("client");
    JarPackage.table = table.init();
});
